package com.xxhong.xxtv.service;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Environment;

import com.xxhong.xxtv.domain.Poems;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public final class MovieList {

    public static List<Poems> list;

    public static List<Poems> setupMovies(Context context) {
        list = new ArrayList<Poems>();
        File file = new File(Environment.getExternalStorageDirectory().getPath(), "ts1.db");
        SQLiteDatabase db = context.openOrCreateDatabase(file.getAbsolutePath(), Context.MODE_PRIVATE, null);
        Cursor cursor = db.rawQuery("select * from bt_author order by author_py asc",new String[]{});
        while(cursor.moveToNext()){
            String author = cursor.getString(cursor.getColumnIndex("author"));
            Poems poems = new Poems();
            poems.setAuthor(author);
            list.add(poems);
        }
        return list;
    }


    public static List<Poems> getPeomsByAuthor(Context context,String authorName) {
        list = new ArrayList<Poems>();
        File file = new File(Environment.getExternalStorageDirectory().getPath(), "ts1.db");
        SQLiteDatabase db = context.openOrCreateDatabase(file.getAbsolutePath(), Context.MODE_PRIVATE, null);
        Cursor cursor = db.rawQuery("select * from bt_poem where author = ? order by author_py asc",new String[]{authorName});
        while(cursor.moveToNext()){
            String poem_id = cursor.getString(cursor.getColumnIndex("poem_id"));
            String class_id = cursor.getString(cursor.getColumnIndex("class_id"));
            String poem_link = cursor.getString(cursor.getColumnIndex("poem_link"));
            String poem_kind = cursor.getString(cursor.getColumnIndex("poem_kind"));
            String author = cursor.getString(cursor.getColumnIndex("author"));
            String image_url = cursor.getString(cursor.getColumnIndex("image_url"));
            String author_py = cursor.getString(cursor.getColumnIndex("author_py"));
            String title = cursor.getString(cursor.getColumnIndex("title"));
            String title_py = cursor.getString(cursor.getColumnIndex("title_py"));
            String content = cursor.getString(cursor.getColumnIndex("content"));
            String content_py = cursor.getString(cursor.getColumnIndex("content_py"));
            String poem_desc = cursor.getString(cursor.getColumnIndex("poem_desc"));
            String poem_desc2 = cursor.getString(cursor.getColumnIndex("poem_desc2"));
            String poem_desc3 = cursor.getString(cursor.getColumnIndex("poem_desc3"));
            String next_id = cursor.getString(cursor.getColumnIndex("next_id"));
            String last_id = cursor.getString(cursor.getColumnIndex("last_id"));
            Poems poems = new Poems();
            poems.setPoem_id(poem_id);
            poems.setAuthor_py(author_py);
            poems.setAuthor(author);
            poems.setPoem_desc(poem_desc);
            poems.setPoem_desc2(poem_desc2);
            poems.setPoem_desc3(poem_desc3);
            poems.setContent(content);
            poems.setContent_py(content_py);
            poems.setPoem_link(poem_link);
            poems.setTitle(title);
            poems.setTitle_py(title_py);
            poems.setPoem_kind(poem_kind);
            list.add(poems);
        }
        return list;
    }


    private static Poems buildMovieInfo(String category, String title,
                                        String description, String studio, String videoUrl, String cardImageUrl,
                                        String bgImageUrl) {
        Poems movie = new Poems();

        return movie;
    }
}
